import React from "react";
import {ScrollView, View} from "react-native";
import chjStyle from "../../../CustomStyle";
import ModuleCommonHeader from "../../module/ModuleCommonHeader";
import CarCockpit from "./CarCockpit";
import Util from "../../Util";
import SingleSelectionTextItem from "../common/SingleSelectionTextItem";
import InputTextItem from "../common/InputTextItem";
import NextButton from "../common/NextButton";
import {Actions} from "react-native-router-flux";

export default class CarEngine extends React.Component
{
    // 构造函数，可执行初始化操作
    constructor(props)
    {
        super(props);
        // 在ES6，在构造函数里初始化state
        this.state = {
        };

        if (!Util.selectCar.carengine)
        {
            Util.selectCar.carengine = Util.defaultCarengine();
        }
    }

    // 组件被加载时
    componentDidMount()
    {

    }

    // 组件即将被卸载时
    componentWillUnmount()
    {
    }

    // 组件被渲染时
    render()
    {
        return(
            <View style={chjStyle.mainContainer}>
                <ModuleCommonHeader title='车辆引擎舱(05)' clickedLeft={this.clickedBack.bind(this)} leftText='返回' clickedRight={this.clickedNew.bind(this)} rightText='保存'/>
                <ScrollView
                    style={chjStyle.mainList}>
                    {
                        Util.selectCar.carengine.map((item, i)=>this.renderItem(item, i))
                    }
                </ScrollView>
                <NextButton onClickedListener={()=>this.clickedNew()}/>
            </View>
        );
    }

    renderItem(item, i)
    {
        if (i <= 11)
        {
            return (<SingleSelectionTextItem object={item} optionArray={[{name:"无"}, {name:"轻微"}, {name:"严重"}]}/>);
        }
        else if(i <= 16)
        {
            return (<SingleSelectionTextItem object={item} optionArray={[{name:"正常"}, {name:"缺少"}, {name:"偏高"}]}/>);
        }
        else if (i === 17)
        {
            return (<SingleSelectionTextItem object={item} optionArray={[{name:"正常"}, {name:"异常"}]}/>);
        }
        else
        {
            return (<InputTextItem object={item} autoCapitalize={'characters'} keyboardType={'default'} maxLength={19}/>);
        }
    }

    clickedBack()
    {
        Actions.pop();
    }

    clickedNew()
    {
        Util.saveData('cars', Util.selectCar);
        Actions.CarCockpit(
            {
                name:'CarCockpit',
                component:CarCockpit,
            }
        );
    }
}
